<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <crudOperation :permission="permission">
      </crudOperation>
      <!-- 表单-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0"
                 :title="crud.status.title" width="80vwpx">
        <el-form ref="form" :model="form" :rules="rules" inline size="small" label-width="auto">

          <el-divider content-position="left">基础信息</el-divider>
          <el-form-item label="编码" prop="code">
            <el-input v-model="form.code" style="width: 240px;"/>
          </el-form-item>
          <el-form-item label="名称" prop="name">
            <el-input v-model="form.name" style="width: 240px;"/>
          </el-form-item>

          <el-form-item label="价格套">
            <zSelect :value.sync="form.priceSuitId" url="api/dropDown/basGoodsPriceSuitList" style="width:  240px;"/>
          </el-form-item>

          <el-form-item label="销售体系类型">
            <el-select v-model="form.type" class="edit-input" placeholder="请选择销售体系类型" style="width: 240px;">
              <el-option
                  v-for="(item,index) in dict.t_bas_sale_system_type"
                  :key="index"
                  v-if="item.seq>0"
                  :label="item.label"
                  :value="item.value"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="排序">
            <el-input-number v-model="form.seq" :min="1" label="排序" style="width: 240px;"></el-input-number>
          </el-form-item>

          <el-form-item label="状态" prop="status">
            <el-select v-model="form.status" class="edit-input" placeholder="请选择" style="width: 240px;">
              <el-option
                  v-for="(item,index) in dict.common_status"
                  :key="index"
                  v-if="item.seq>0"
                  :label="item.label"
                  :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" type="textarea" style="width: 240px;"/>
          </el-form-item>


          <el-divider content-position="left">取价方式</el-divider>
          <el-form-item label="销售取价">
            <el-select v-model="form.saleSystem" class="edit-input" placeholder="请选择销售取价类型" style="width: 240px;">
              <el-option
                  v-for="(item,index) in dict.t_bas_sale_system_sale_system"
                  :key="index"
                  v-if="item.seq>0"
                  :label="item.label"
                  :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="退货取价">
            <el-select v-model="form.saleReturnSystem" class="edit-input" placeholder="请选择退货取价类型" style="width: 240px;">
              <el-option
                  v-for="(item,index) in dict.t_bas_sale_system_return_system"
                  :key="index"
                  v-if="item.seq>0"
                  :label="item.label"
                  :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="退货取价时间设置" prop="saleReturnSystemTime">
            <el-input v-model="form.saleReturnSystemTime" style="width: 240px;">
              <template slot="append">月</template>
            </el-input>
          </el-form-item>
          <el-form-item label="退货历史检查时间" prop="saleReturnSystemHisCheckTime">
            <el-input v-model="form.saleReturnSystemHisCheckTime" style="width: 240px;">
              <template slot="append">月</template>
            </el-input>
          </el-form-item>

          <el-divider content-position="left">订单审核</el-divider>
          <el-form-item label="超账期审核控制">
            <el-select v-model="form.saleOrderPassOverDateLimit" class="edit-input" placeholder="请选择超账期审核控制" style="width: 240px;">
              <el-option
                  v-for="(item,index) in dict.t_bas_sale_system_sale_order_pass_over_date_limit"
                  :key="index"
                  v-if="item.seq>0"
                  :label="item.label"
                  :value="item.value"
              />
            </el-select>
          </el-form-item>
          <div style="display: flex;align-items: center;float: right">
            <el-form-item label="商品零金额限制">
              <el-switch
                  v-model="form.saleOrderPassZeroAmountLimit"
                  active-color="#13ce66"
                  :active-value="1"
                  :inactive-value="0"
                  inactive-color="#ff4949">
              </el-switch>
            </el-form-item>
            <el-form-item label="现金客户余额限制" style="margin-left: 20px">
              <el-switch
                  v-model="form.saleOrderPassCashCustomerBalanceLimit"
                  active-color="#13ce66"
                  :active-value="1"
                  :inactive-value="0"
                  inactive-color="#ff4949">
              </el-switch>
            </el-form-item>
          </div>

          <el-divider content-position="left">自动验收</el-divider>
          <div style="display: flex;align-items: center;">
            <el-form-item label="销售回单自动审核">
              <el-switch
                  v-model="form.saleDeliveryReceiptAutoPass"
                  active-color="#13ce66"
                  :active-value="1"
                  :inactive-value="0"
                  inactive-color="#ff4949">
              </el-switch>
            </el-form-item>
            <el-form-item label="退货自动审核" style="margin-left: 20px">
              <el-switch
                  v-model="form.saleReturnReceiptAutoPass"
                  active-color="#13ce66"
                  :active-value="1"
                  :inactive-value="0"
                  inactive-color="#ff4949">
              </el-switch>
            </el-form-item>
          </div>


        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>

      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu>
      <!-- 表格配置 -->
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header"  @tabSave="tabSave" @pit="pit" />
      </el-dialog>

      <!--表格渲染-->
      <el-table ref="table"  border
                height="700"
                show-summary
                @cell-dblclick="row=>crud.toEdit(row)"
                v-loading="crud.loading"
                :data="crud.data"
                size="small"
                style="width: 100%;"
                v-if="isShowTable"
                @header-dragend="changeColWidth"
                @contextmenu.native="showMenu"
                :summary-method="crud.sumRow"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column :render-header="crud.renderHeader" type="selection" width="60"/>
        <el-table-column :render-header="crud.renderHeader" type="index" width="60" label="序号"/>
        <el-table-column
          v-if="item.visible"
          v-for="(item, index) in crud.header"
          :key="`col_${index}`"
          :prop="item.prop"
          :label="columnLabel(item)"
          :width="item.width + 'px'"
          :data-porp='item.prop'
          @contextmenu.native="showMenu"
          @header-dragend="changeColWidth"
        >
          <!-- 自定义渲染模版 -->
          <template slot-scope="scope">
            <!-- 当列key为 sort 时，渲染一个手柄icon -->
            <template v-if="item.prop =='sort'">
              <div class="handle_move">
                <i :class="scope.row['sort']" />
              </div>
            </template>
            <template v-else>
              <span v-if="item.type == 1" style="margin-left: 0px">{{scope.row[`${item.prop}`]}}</span>
              <span v-if="item.type == 2" style="margin-left: 0px">{{ parseTime(scope.row[`${item.prop}`])}}</span>
              <span v-if="item.type == 3" style="margin-left: 0px">{{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}</span>
            </template>
          </template>
        </el-table-column>
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('code')" prop="code" label="编码"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('name')" prop="name" label="名称"/>-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('type')" prop="type" label="销售体系类型"/>&ndash;&gt;-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('priceSuitName')" prop="priceSuitName" label="价格套名称"/>-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('saleSystem')" prop="saleSystem"&ndash;&gt;-->
<!--&lt;!&ndash;                         label="销售取价"/>&ndash;&gt;-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('saleReturnSystem')" prop="saleReturnSystem"&ndash;&gt;-->
<!--&lt;!&ndash;                         label="销售退货取价"/>&ndash;&gt;-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('saleReturnSystemTime')" prop="saleReturnSystemTime"&ndash;&gt;-->
<!--&lt;!&ndash;                         label="销售退货取价时间设置(月)"/>&ndash;&gt;-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('saleReturnSystemHisCheckTime')" prop="saleReturnSystemHisCheckTime"&ndash;&gt;-->
<!--&lt;!&ndash;                         label="销售退货历史检查时间(月)"/>&ndash;&gt;-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('saleOrderPassOverDateLimit')" prop="saleOrderPassOverDateLimit"&ndash;&gt;-->
<!--&lt;!&ndash;                         label="销售订单审核超账期控制"/>&ndash;&gt;-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('saleOrderPassZeroAmountLimit')" prop="saleOrderPassZeroAmountLimit"&ndash;&gt;-->
<!--&lt;!&ndash;                         label="销售订单审核零金额审核限制"/>&ndash;&gt;-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('saleOrderPassCashCustomerBalanceLimit')"&ndash;&gt;-->
<!--&lt;!&ndash;                         prop="saleOrderPassCashCustomerBalanceLimit" label="销售订单审核现金客户余额限制"/>&ndash;&gt;-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('saleDeliveryReceiptAutoPass')" prop="saleDeliveryReceiptAutoPass"&ndash;&gt;-->
<!--&lt;!&ndash;                         label="发货单审核后销售回单自动审核"/>&ndash;&gt;-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('saleReturnReceiptAutoPass')" prop="saleReturnReceiptAutoPass"&ndash;&gt;-->
<!--&lt;!&ndash;                         label="退货入库单审核后退货单自动审核"/>&ndash;&gt;-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('seq')" prop="seq" label="排序"/>&ndash;&gt;-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('status')" prop="status" label="状态(0:禁用 1:启用)"/>&ndash;&gt;-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('remark')" prop="remark" label="备注"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('status')" prop="status" label="状态">-->
<!--          <template slot-scope="scope">-->
<!--            {{ dict.label.common_status[scope.row.status] }}-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-permission="['admin','basSaleSystem:edit','basSaleSystem:del']" label="操作" width="150px"-->
<!--                         align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <udOperation-->
<!--                :data="scope.row"-->
<!--                :permission="permission"-->
<!--            />-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination/>
    </div>
  </div>
</template>

<script>
import crudBasSaleSystem from '@/api/erp/basSaleSystem'
import CRUD, {crud, form, header, presenter} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

import { publicListKey } from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
import {tablemixins} from "@/mixins/tablemixins";
import  jTableColumnConfig  from "@/components/jTableColumnConfig/jTableColumnConfig";

// crud交由presenter持有
const defaultCrud = CRUD({title: '销售体系', url: 'api/basSaleSystem', sort: 'code,asc', crudMethod: {...crudBasSaleSystem}})
const defaultForm = {
  id: null,
  code: null,
  name: null,
  type: null,
  priceSuitId: null,
  priceSuitCode: null,
  priceSuitName: null,
  saleSystem: null,
  saleReturnSystem: null,
  saleReturnSystemTime: null,
  saleReturnSystemHisCheckTime: null,
  saleOrderPassOverDateLimit: null,
  saleOrderPassZeroAmountLimit: null,
  saleOrderPassCashCustomerBalanceLimit: null,
  saleDeliveryReceiptAutoPass: null,
  saleReturnReceiptAutoPass: null,
  seq: null,
  status: null,
  remark: null,
  createUserId: null,
  createUserCode: null,
  createUserName: null,
  createTime: null,
  updateUserId: null,
  updateUserCode: null,
  updateUserName: null,
  updateTime: null
}
export default {
  name: 'BasSaleSystem',
  components: {pagination, crudOperation, rrOperation, udOperation,jTableColumnConfig},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),publicListKey,tablemixins],
  dicts: ['t_bas_sale_system_type', 'common_status','t_bas_sale_system_sale_system','t_bas_sale_system_return_system','t_bas_sale_system_sale_order_pass_over_date_limit'],

  data() {
    return {

      permission: {
        add: ['admin', 'basSaleSystem:add'],
        edit: ['admin', 'basSaleSystem:edit'],
        del: ['admin', 'basSaleSystem:del'],
        import: ['admin', 'basSaleSystem:import'],
        export: ['admin', 'basSaleSystem:export'],
        copy: ['admin', 'basSaleSystem:copy'],
        upload: ['admin', 'basSaleSystem:upload'],
        download: ['admin', 'basSaleSystem:download'],
        enable: ['admin', 'basSaleSystem:enable'],
        disable: ['admin', 'basSaleSystem:disable'],
      },
      rules: {
        saleReturnSystemTime: [
          {required: true, message: '销售退货取价时间设置(月)不能为空', trigger: 'blur'}
        ],
        saleReturnSystemHisCheckTime: [
          {required: true, message: '销售退货历史检查时间(月)不能为空', trigger: 'blur'}
        ],
        name: [
          {required: true, message: '名称不能为空', trigger: 'blur'}
        ],
        code: [
          {required: true, message: '编码不能为空', trigger: 'blur'}
        ],
      }
    }
  },
  watch: {},
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },

  }
}
</script>

<style scoped>
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
</style>
